package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.service.ISysConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.MesPackage;
import com.ruoyi.order.service.IMesPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品装箱Controller
 * 
 * @author guoxl
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/order/package")
public class MesPackageController extends BaseController
{
    @Autowired
    private IMesPackageService mesPackageService;

    @Autowired
    private ISysConfigService configService;
    /**
     * 查询产品装箱列表
     */
    @PreAuthorize("@ss.hasPermi('order:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesPackage mesPackage)
    {
        startPage();
        List<MesPackage> list = mesPackageService.selectMesPackageList(mesPackage);
        return getDataTable(list);
    }

    /**
     * 导出产品装箱列表
     */
    @PreAuthorize("@ss.hasPermi('order:package:export')")
    @Log(title = "产品装箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPackage mesPackage)
    {
        List<MesPackage> list = mesPackageService.selectMesPackageList(mesPackage);
        ExcelUtil<MesPackage> util = new ExcelUtil<MesPackage>(MesPackage.class);
        util.exportExcel(response, list, "产品装箱数据");
    }

    /**
     * 获取产品装箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:package:query')")
    @GetMapping(value = "/{packId}")
    public AjaxResult getInfo(@PathVariable("packId") Long packId)
    {
        return success(mesPackageService.selectMesPackageByPackId(packId));
    }

    /**
     * 新增产品装箱
     */
    @PreAuthorize("@ss.hasPermi('order:package:add')")
    @Log(title = "产品装箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPackage mesPackage)
    {
        return toAjax(mesPackageService.insertMesPackage(mesPackage));
    }

    /**
     * 修改产品装箱
     */
    @PreAuthorize("@ss.hasPermi('order:package:edit')")
    @Log(title = "产品装箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPackage mesPackage)
    {
        return toAjax(mesPackageService.updateMesPackage(mesPackage));
    }

    /**
     * 删除产品装箱
     */
    @PreAuthorize("@ss.hasPermi('order:package:remove')")
    @Log(title = "产品装箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packIds}")
    public AjaxResult remove(@PathVariable Long[] packIds)
    {
        return toAjax(mesPackageService.deleteMesPackageByPackIds(packIds));
    }
    /**
     * 发送工厂产品装箱
     */
    @Log(title = "发送产品装箱")
	@GetMapping("/send/{packIds}")
    public AjaxResult sendPackage(@PathVariable Long[] packIds)
    {
        String url = configService.selectConfigByKey("topmes_service_url");
        return toAjax(mesPackageService.sendPackageByPackIds(packIds, url));
    }
}
